package com.ifgi.sitcom.campusmapperNDrawer.dialogs;



import java.text.DecimalFormat;
import java.util.ArrayList;

import org.osmdroid.views.overlay.OverlayItem;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockDialogFragment;
import com.gamificationlibrary.model.leaderboard.Leaderboard;
import com.gamificationlibrary.model.*;
import com.ifgi.sitcom.campusmapperNDrawer.R;
import com.ifgi.sitcom.campusmapperNDrawer.adapters.ListViewOwnersAdapter;
import com.ifgi.sitcom.campusmapperNDrawer.gamedata.PlayerAdapter;
import com.ifgi.sitcom.campusmapperNDrawer.indoordata.FloorPlan;
import com.ifgi.sitcom.campusmapperNDrawer.outdoordata.Building;
/*
 * 
 *  dialog  shown when room was created/ edited
 */
public class OwnerDialog extends SherlockDialogFragment {

	private Ownership<Building> buildingItem;
	private ArrayList<Ownership<FloorPlan>> floorsItem;
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog builder = new Dialog(
				getActivity());
		// Get the layout inflater
		LayoutInflater inflater = getActivity().getLayoutInflater();

		// Inflate and set the layout for the dialog
		// Pass null as the parent view because its going in the dialog layout
		View dialogView = inflater.inflate(R.layout.dialog_owners, null);
	
				 builder.setTitle(R.string.owners);
				 
				 builder.setContentView(dialogView);

		// acces view elements
     	
		RelativeLayout layout=(RelativeLayout) dialogView.findViewById(R.id.relativeLayout_owners);
		
		LayoutInflater inflater2 = (LayoutInflater)getActivity().getBaseContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               
		View view = inflater2.inflate(R.layout.item_owner, null);
		ImageView iconBuildingOwner=(ImageView) view.findViewById(R.id.iconOwner);
		iconBuildingOwner.setImageBitmap(((PlayerAdapter) buildingItem.getP()).getPicture().bitmap);
		ImageView crown=(ImageView) view.findViewById(R.id.imageView_crown);
		crown.setVisibility(View.VISIBLE);
		TextView titleView = (TextView) view.findViewById(R.id.text_buildingsOwners);
		titleView.setText("Building '"+buildingItem.getT().getBuildingName()+"' owner");
        TextView usernameView = (TextView) view.findViewById(R.id.textview_usernameOwner);
        usernameView.setTypeface(null, Typeface.BOLD);
        usernameView.setText(((PlayerAdapter) buildingItem.getP()).getUsername());
        TextView descriptionView = (TextView) view.findViewById(R.id.texxtview_scoreOwner);
        descriptionView.setText(String.valueOf(buildingItem.getS().getValue())+" points");
      
		layout.addView(view);


		ListView list = (ListView) dialogView.findViewById(R.id.listview_owners);
		list.setAdapter(new ListViewOwnersAdapter(getActivity(),floorsItem));
	
        builder.setCanceledOnTouchOutside(true);
		
		return builder;
		
	}

	
	public void setFields(Ownership<Building> buildingOwnership, ArrayList<Ownership<FloorPlan>> floorsOwnership)
	{	// TODO Auto-generated method stub
		this.buildingItem=buildingOwnership;
		this.floorsItem=floorsOwnership; 
	}



	
	

}
